<?php

use Illuminate\Database\Seeder;

class UsersTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
		// computer
		$file = fopen("database/seeds/2018_cs.csv","r");
		$id = 1;
		while(!feof($file))
		{
			$info = fgetcsv($file);
			if ($info[2] == "") {
				continue;
			}
	        \App\User::create(['id'=>$id, 'username' => $info[2], 
				'name' => $info[1], 
				'email' => 'xxx@qq.com', 
				'phone' => $info[5], 
				'role' => 2, 
				'password' => bcrypt("123456")]);
			\App\Supervisor::create(['user_id'=>$id, 'major'=>'Computer Science', 'job' => $info[3], 'title' => $info[4], 'quota' => 11]);
			$id += 1;
		}
		fclose($file);

		// math
		$file = fopen("database/seeds/2018_math.csv","r");
		while(!feof($file))
		{
			$info = fgetcsv($file);
			if ($info[2] == "") {
				continue;
			}
	        \App\User::create(['id'=>$id, 'username' => $info[2], 
				'name' => $info[1], 
				'email' => 'xxx@qq.com', 
				'phone' => $info[5], 
				'role' => 2, 
				'password' => bcrypt("123456")]);
			\App\Supervisor::create(['user_id'=>$id, 'major'=>'Mathematics', 'job' => $info[3], 'title' => $info[4], 'quota' => 5]);
			$id += 1;
		}
		fclose($file);

		// student
		$file = fopen("database/seeds/2018_st.csv","r");
		while(!feof($file))
		{
			$info = fgetcsv($file);
			if ($info[2] == "") {
				continue;
			}
	        \App\User::create(['id'=>$id, 'username' => $info[2], 
				'name' => $info[3], 
				'email' => 'xxx@qq.com', 
				'phone' => '', 
				'role' => 1, 
				'password' => bcrypt("123456")]);
			\App\Student::create(['user_id'=>$id, 'class'=>$info[1]]);
			$id += 1;
		}
		fclose($file);
    }
}
